package  
{
	import org.flixel.FlxObject;
	import org.flixel.FlxSprite;
	
	/**
	 * ...
	 * @author maliu
	 */
	public class Bullet extends FlxSprite 
	{
		[Embed(source = "../res/bullet.png")]
		protected var BulletImgRef:Class;
		
		public function Bullet() 
		{
			super(0, 0, null);
			this.loadGraphic(BulletImgRef, true, true, 8, 8);
			this.addAnimation("shootUp", [0]);
			this.addAnimation("shootDown", [1]);
			this.addAnimation("shootLeft", [2]);
			this.addAnimation("shootRight", [3]);
			this.addAnimation("BulletBoom", [4, 5, 6, 7], 12, false);
			
			this.exists = false;
		}
		public function shoot(_sPosX:Number, _sPosY:Number, _velX:Number, _velY:Number):void
		{
			this.reset(_sPosX, _sPosY);
			this.velocity.x = _velX;
			this.velocity.y = _velY;
			
			if (_velY < 0)
			{
				this.play("shootUp");
			}
			else if (_velY > 0)
			{
				this.play("shootDown");
			}
			else if (_velX < 0)
			{
				this.play("shootLeft");
			}
			else if (_velX > 0)
			{
				this.play("shootRight");
			}
		}
		override public function update():void
		{
			if (this.dead && this.finished)
			{
				this.exists = false;
			}
			else
			{
				super.update();
			}
		}
		override public function hitSide(_contact:FlxObject, _velocity:Number):void
		{
			this.hurt(0);
			super.hitSide(_contact, _velocity);
		}
		override public function hitTop(_contact:FlxObject, _velocity:Number):void
		{
			this.hurt(0);
			super.hitTop(_contact, _velocity);
		}
		override public function hitBottom(_contact:FlxObject, _velocity:Number):void
		{
			this.hurt(0);
			super.hitBottom(_contact, _velocity);
		}
		override public function hurt(_damage:Number):void
		{
			if (this.dead)
			{
				return;
			}
			this.dead = true;
			this.velocity.x = 0;
			this.velocity.y = 0;
			this.play("BulletBoom");
			//super.hurt(_damage);
		}
	}

}